﻿package mortal.game.view.guide
{
    import Message.Public.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.game.*;
    import mortal.game.mvc.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.ai.ais.*;
    import mortal.game.scene3D.ai.singleAIs.autofight.*;
    import mortal.game.view.task.data.*;
    import mortal.mvc.core.*;

    public class GuideWhenRelocateCrossServer extends Object
    {
        private var _myPoint:SMovePoint;
        private var _relocateTime:int;
        private var _aiManagerVersion:int;
        private var nowSec:int = 0;
        private var _isAutoFight:Boolean = false;
        private var _range:int = 0;
        private static var _instance:GuideWhenRelocateCrossServer;

        public function GuideWhenRelocateCrossServer()
        {
            return;
        }// end function

        public function startWork(param1:SMovePoint) : void
        {
            this._myPoint = param1;
            if (AutoFightAI.isWorking)
            {
                this._isAutoFight = true;
                this._range = AutoFightBossSelectAI.instance.range;
            }
            this._relocateTime = getTimer();
            Global.instance.removeEnterSecond(this.everySecond);
            Dispatcher.removeEventListener(EventName.Scene_Update, this.sceneUpdateHandler);
            Dispatcher.addEventListener(EventName.Scene_Update, this.sceneUpdateHandler);
            return;
        }// end function

        private function sceneUpdateHandler(param1 = null) : void
        {
            var _loc_3:SPassTo = null;
            Dispatcher.removeEventListener(EventName.Scene_Update, this.sceneUpdateHandler);
            var _loc_2:* = getTimer();
            if (_loc_2 - this._relocateTime > 5000)
            {
                return;
            }
            if (this._isAutoFight)
            {
                if (GuideAutoFightWin.instance.isHide)
                {
                    GuideAutoFightWin.instance.show();
                }
                _loc_3 = GameController.taskImpl.getAutoFightPoint(-1, false, true);
                GuideAutoFightWin.instance.startWork(_loc_3, this._range);
            }
            Alert.show(Language.getString(21031), null, Alert.OK);
            this.nowSec = 0;
            Global.instance.addEnterSecond(this.everySecond);
            return;
        }// end function

        private function everySecond() : void
        {
            var _loc_1:int = 0;
            var _loc_2:SPassTo = null;
            var _loc_3:String = this;
            var _loc_4:* = this.nowSec + 1;
            _loc_3.nowSec = _loc_4;
            if (this.nowSec == 2)
            {
                this._aiManagerVersion = AIManager.version;
            }
            if (this.nowSec == 30)
            {
                Alert.removeAllAlertWin();
            }
            if (this.nowSec >= 3600)
            {
                Global.instance.removeEnterSecond(this.everySecond);
                _loc_1 = AIManager.version;
                if (this._aiManagerVersion == _loc_1)
                {
                    _loc_2 = new SPassTo();
                    _loc_2.mapId = this._myPoint.mapId;
                    _loc_2.toPoint = new SPoint();
                    _loc_2.toPoint.x = this._myPoint.x;
                    _loc_2.toPoint.y = this._myPoint.y;
                    if (this._isAutoFight)
                    {
                        if (GuideAutoFightWin.instance.isHide)
                        {
                            GuideAutoFightWin.instance.show();
                        }
                        GuideAutoFightWin.instance.startWork(_loc_2, this._range);
                    }
                    else if (TaskUtil.canFlyByNoBuyFlyBoot())
                    {
                        AIManager.onAIControl(AIType.FlyBoot, _loc_2);
                    }
                    else
                    {
                        AIManager.onAIControl(AIType.GoToOtherMap, Game.mapInfo.mapId, _loc_2.mapId, new Point(this._myPoint.x, this._myPoint.y));
                    }
                }
            }
            return;
        }// end function

        public static function get instance() : GuideWhenRelocateCrossServer
        {
            if (_instance == null)
            {
                _instance = new GuideWhenRelocateCrossServer;
            }
            return _instance;
        }// end function

    }
}
